﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;

using 纸片人.InterfaceFolder;
using 纸片人.win2dEffectControl;
using 纸片人.win2dEffectControl.DataClass;

// The Templated Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234235

namespace 纸片人.CalculateControls
{
    public abstract class CalculateControl : ProviderDataControl,IValueChange
    {

      

        public event ValueChangedHeader ValueChangeing;
        public event ValueChangedHeader ValueChanged;

        public CalculateControl()
        {
            this.DefaultStyleKey = typeof(CalculateControl);
            
        }


        protected void OnValueChanged(object sender ,object value) 
        {
            ValueChanged?.Invoke(sender, value);
        }

        protected void OnValueChanging(object sender,object value)
        {
            ValueChangeing?.Invoke(sender, value);
        }

        /// <summary>
        /// 获取指定对象的指定属性并返回
        /// </summary>
        /// <param name="export">指定的对象</param>
        /// <param name="valueName">指定的属性名</param>
        /// <returns>返货获取到的属性或者null</returns>
        protected object GetProvideValue(IExporter export,string valueName)
        {
            if(export!= null)
            {
                var type =export.GetType();
                var properties = type.GetProperties().ToList();
                var propertie = properties.Find(p =>  p.Name == valueName);
                var value = propertie.GetValue(export);
                return value;
            }
            return null;
        }
    }
}
